home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / devices and hardware / scsi / scsi driveid sample / showsystemvolumeid.c < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.0 KB  |  86 lines

  1. /*
  2.     File:        ShowSystemVolumeID.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Martin Minow    
  7.  
  8.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/14/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #include <Folders.h>
  24. #include <GestaltEqu.h>
  25. #include <Files.h>
  26. #include <Devices.h>
  27. #include <Memory.h>
  28. #include <Traps.h>
  29. #include <stdio.h>
  30. void                    ShowSystemVolumeName(void);
  31. void                    ShowSCSIDeviceIdent(
  32.         short                driverRefNum
  33.     );
  34.  
  35. static void
  36. ClearMemory(
  37.         Ptr                ptr,
  38.         Size            size
  39.     )
  40. {
  41.         while (size > 0) {
  42.             *ptr++ = 0;
  43.             --size;
  44.         }
  45. }
  46.  
  47.  
  48. void
  49. ShowSystemVolumeName(void)
  50. {
  51.         OSErr                    status;
  52.         long                    gestaltResult;
  53.         short                    systemVRefNum;
  54.         long                    systemFolderDirID;
  55.         HVolumeParam            pb;
  56.         Str255                    systemVolumeName;
  57.                 
  58.         status = Gestalt(gestaltFindFolderAttr, &gestaltResult);
  59.         if (status == noErr) {                /* We have FindFolder                */
  60.             status = FindFolder(
  61.                         kOnSystemDisk,
  62.                         kSystemFolderType,
  63.                         kDontCreateFolder,
  64.                         &systemVRefNum,
  65.                         &systemFolderDirID
  66.                     );
  67.         }
  68.         if (status == noErr) {
  69.             ClearMemory((Ptr) &pb, sizeof pb);
  70.             pb.ioVolIndex = 0;
  71.             pb.ioNamePtr = systemVolumeName;
  72.             pb.ioVRefNum = systemVRefNum;
  73.             status = PBHGetVInfoSync((HParmBlkPtr) &pb);
  74.         }
  75.         if (status == noErr) {
  76.             printf("Boot volume \"%.*s\", drive %d, driver %d",
  77.                 systemVolumeName[0],
  78.                 &systemVolumeName[1],
  79.                 pb.ioVDrvInfo,
  80.                 pb.ioVDRefNum
  81.             );
  82.             ShowSCSIDeviceIdent(pb.ioVDRefNum);
  83.             printf("\n");
  84.         }
  85. }
  86.